/*
 *
 *  Copyright (C) 2010 Tal Eisenberg
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package tal.drivechain.chain.shell;

import java.io.PrintStream;
import tal.drivechain.chain.Chain;
import tal.drivechain.chain.ChainNode;
import tal.drivechain.system.Globals;

/**
 *
 * @author eisental
 */
public class ActiveChainObject extends ShellObject {

    private ChainObject chainObj;

    public ActiveChainObject(DriveShell shell) {
        super("activeChain", "activeChains", "active", shell);
        chainObj = new ChainObject(shell);
    }

    @Override
    public void setPrintStream(PrintStream out) {
        super.setPrintStream(out);
        chainObj.setPrintStream(out);
    }
    @Override
    public boolean isActionSupported(Action action) {
        return (action!=Action.make && action!=Action.list && action!=Action.remove);
    }

    @Override
    public void set(String command) throws IllegalArgumentException {
        ChainNode node = Globals.findNode(command, shell.getActiveChain());
        if (!(node instanceof Chain)) throw new IllegalArgumentException("Node " + node.getPath() + " is not a chain.");
        Chain chain = (Chain)node;
        if (chain==null)
            throw new IllegalArgumentException("Chain '" + command + "' doesn't exist.");
        shell.setActiveChain(chain);
    }

    @Override
    public void inspect(String command) throws IllegalArgumentException {
        String chainName = shell.getActiveChain().getPath();
        chainObj.inspect(chainName);
    }

    @Override
    public void make(String command) throws IllegalArgumentException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void remove(String command) throws IllegalArgumentException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void list() throws IllegalArgumentException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}
